from django.db import models
from dvadmin.utils.models import CoreModel

# Create your models here.

class HardwareClass(CoreModel):
    """硬件类别字典"""

    title = models.CharField(max_length=32, unique=True, verbose_name="硬件类别")
    name = models.CharField(max_length=32, unique=True, verbose_name="类别名称")
    remark = models.CharField(max_length=256, null=True, blank=True, verbose_name="备注")

    class Meta:
        db_table = "secmdb_hardwareclass"
        verbose_name = "硬件类型字典"
        verbose_name_plural = verbose_name
        ordering = ("title",)

class ServiceClass(CoreModel):
    """服务类别字典"""

    title = models.CharField(max_length=32, unique=True, verbose_name="服务类别")
    name = models.CharField(max_length=64, unique=True, verbose_name="类别名称")
    downtime_level = models.CharField(max_length=256, null=True, blank=True, verbose_name="停机复原指标")
    downtime_service = models.CharField(max_length=256, null=True, blank=True, verbose_name="停机服务指标")
    disaster_level = models.CharField(max_length=256, null=True, blank=True, verbose_name="灾难复原指标")
    disaster_service = models.CharField(max_length=256, null=True, blank=True, verbose_name="灾难服务指标")
    remark = models.CharField(max_length=256, null=True, blank=True, verbose_name="备注")

    class Meta:
        db_table = "secmdb_serviceclass"
        verbose_name = "服务类别字典"
        verbose_name_plural = verbose_name
        ordering = ("title",)

class Server(CoreModel):
    """服务器表"""

    # 物理机特有栏位
    hw_class = models.ForeignKey(HardwareClass, null=True, blank=True, default=None, on_delete=models.SET_DEFAULT, verbose_name="硬件类别")
    manufacturer = models.CharField(max_length=64, null=True, blank=True, verbose_name="制造商")
    model = models.CharField(max_length=64, null=True, blank=True, verbose_name="服务器型号")
    sn = models.CharField(max_length=64, null=True, blank=True, verbose_name="SN")
    astag = models.CharField(max_length=64, null=True, blank=True, verbose_name="资产标签")
    serverroom = models.CharField(max_length=64, null=True, blank=True, verbose_name="机房")
    rack = models.CharField(max_length=64, null=True, blank=True, verbose_name="机柜")
    rack_unit = models.CharField(max_length=64, null=True, blank=True, verbose_name="机架位")
    spec_disk = models.CharField(max_length=256, null=True, blank=True, verbose_name="硬盘详情")
    spec_special = models.CharField(max_length=256, null=True, blank=True, verbose_name="特殊配置")
    bmc_ip = models.CharField(max_length=128, null=True, blank=True, verbose_name="BMC IP")
    bmc_version = models.CharField(max_length=64, null=True, blank=True, verbose_name="BMC版本")
    bmc_account = models.CharField(max_length=128, null=True, blank=True, verbose_name="BMC账号")
    bmc_passwd = models.CharField(max_length=128, null=True, blank=True, verbose_name="BMC密码")

    # 虚拟机特有栏位
    vmid = models.CharField(max_length=16, null=True, blank=True, verbose_name="VM编号")
    vmhost = models.CharField(max_length=64, null=True, blank=True, verbose_name="宿主机")
    vmtool = models.CharField(max_length=64, null=True, blank=True, verbose_name="Tool状态")
    vmdatastore = models.CharField(max_length=64, null=True, blank=True, verbose_name="数据存储")
    nics = models.SmallIntegerField(null=True, blank=True, verbose_name="网卡数量")
    disk_num = models.SmallIntegerField(null=True, blank=True, verbose_name="硬盘数量")

    # 基础公共栏位
    service_class = models.ForeignKey(ServiceClass, null=True, blank=True, default=None, on_delete=models.SET_DEFAULT, verbose_name="服务类别")
    name = models.CharField(max_length=64, unique=True, verbose_name="服务器名称")
    hostname = models.CharField(max_length=64, null=True, blank=True, verbose_name="主机名")
    domain = models.CharField(max_length=32, null=True, blank=True, verbose_name="域名")
    os_type = models.CharField(max_length=32, null=True, blank=True, verbose_name="操作系统类型")
    os_version = models.CharField(max_length=64, null=True, blank=True, verbose_name="操作系统版本")
    ipaddress = models.CharField(max_length=128, null=True, blank=True, verbose_name="IP地址")
    backup_ip = models.CharField(max_length=128, null=True, blank=True, verbose_name="备份IP")
    sub_ipaddress = models.CharField(max_length=128, null=True, blank=True, verbose_name="子IP地址")
    cpu_model = models.CharField(max_length=128, null=True, blank=True, verbose_name="CPU型号")
    cpu_socket = models.SmallIntegerField(null=True, blank=True, verbose_name="CPU插槽数")
    cpu_cores = models.SmallIntegerField(null=True, blank=True, verbose_name="CPU核数")
    mem_num = models.SmallIntegerField(null=True, blank=True, verbose_name="内存条数")
    mem_size = models.SmallIntegerField(null=True, blank=True, verbose_name="内存大小")
    disk_size = models.SmallIntegerField(null=True, blank=True, verbose_name="磁盘大小")
    is_vm = models.BooleanField(default=False, verbose_name="是否虚拟机")

    # 公共管理信息栏位
    owner_func = models.CharField(max_length=64, null=True, blank=True, verbose_name="所属部门")
    owner = models.CharField(max_length=64, null=True, blank=True, verbose_name="负责人")
    owner_leader = models.CharField(max_length=64, null=True, blank=True, verbose_name="负责人领导")
    form_online = models.CharField(max_length=64, null=True, blank=True, verbose_name="上线时间")
    form_offline = models.CharField(max_length=64, null=True, blank=True, verbose_name="下线时间")
    # superuser = models.CharField(max_length=64, null=True, blank=True, verbose_name="超级用户")
    # superpasswd = models.CharField(max_length=64, null=True, blank=True, verbose_name="超级密码")
    remark = models.CharField(max_length=256, null=True, blank=True, verbose_name="备注")

    class Meta:
        db_table = "secmdb_server"
        verbose_name = "服务器总表"
        verbose_name_plural = verbose_name


class SrvAccount(CoreModel):
    """服务器账户表"""

    server = models.ForeignKey(Server, on_delete=models.SET_DEFAULT, default=None, verbose_name="服务器")
    account = models.CharField(max_length=64, null=True, blank=True, verbose_name="账户")
    current_passwd = models.CharField(max_length=64, null=True, blank=True, verbose_name="当前密码")
    passwd_expire = models.DateField(null=True, blank=True, verbose_name="密码过期时间")
    last_passwd = models.CharField(max_length=64, null=True, blank=True, verbose_name="上次密码")
    last_change = models.DateField(null=True, blank=True, verbose_name="上次密码修改时间")
    next_passwd = models.CharField(max_length=64, null=True, blank=True, verbose_name="下次密码")
    next_change = models.DateField(null=True, blank=True, verbose_name="下次密码修改时间")
    is_change = models.BooleanField(default=False, verbose_name="是否需要修改")
    remark = models.CharField(max_length=256, null=True, blank=True, verbose_name="备注")

    class Meta:
        db_table = "secmdb_srvaccount"
        verbose_name = "服务器账户表"
        verbose_name_plural = verbose_name
        ordering = ("server", "account")












    
    









    


